import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
import cart from './modules/cart'
import address from './modules/address'
import search from './modules/search'
import { isLogin } from '@/api/login'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
  },
  getters: {
    // token (state) {
    //   return state.user.userInfo.token
    // }
  },
  mutations: {
  },
  actions: {
    async checkLoginStatus () {
      try {
        const res = await isLogin()
        if (res.data && res.data.isLoggedIn) {
          return true
        }
        return false
      } catch (error) {
        console.error('登录状态检查失败:', error)
        return false
      }
    }
  },
  modules: {
    user,
    cart,
    address,
    search
  }
})

export default store
